Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cortex-M: NVIC and SCB code duplication cleanup #576

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

agkaminski
Copy link
Member

@agkaminski agkaminski commented Aug 9, 2024

Clenup standard part of Cortex-M component (i.e. SCB and NVIC) mass copy-paste across targets. If this approach passes, then it will be done over plo too

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (mcxn94x).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

hal/arm/nvic.c Outdated Show resolved Hide resolved
hal/arm/Makefile Outdated Show resolved Hide resolved
hal/arm/nvic.c Outdated Show resolved Hide resolved
hal/arm/nvic.h Outdated Show resolved Hide resolved
@agkaminski agkaminski force-pushed the agkaminski/nvic_unite branch 2 times, most recently from 6cf7ca5 to 43092c6 Compare August 9, 2024 12:09
hal/arm/scb.c Outdated Show resolved Hide resolved
hal/arm/scb.c Outdated Show resolved Hide resolved
@agkaminski agkaminski marked this pull request as ready for review August 9, 2024 12:15
@agkaminski agkaminski requested a review from Darchiv August 9, 2024 12:29
Copy link

github-actions bot commented Aug 9, 2024

Unit Test Results

7 700 tests  ±0   6 985 ✅ ±0   39m 14s ⏱️ - 1m 5s
  436 suites ±0     715 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 4762279. ± Comparison against base commit bcc5c41.

♻️ This comment has been updated with latest results.

@agkaminski agkaminski force-pushed the agkaminski/nvic_unite branch 2 times, most recently from 191c1c9 to 3b69d3d Compare August 9, 2024 13:53
hal/arm/scb.c Outdated Show resolved Hide resolved
hal/arm/scb.c Outdated Show resolved Hide resolved
hal/arm/scb.c Outdated Show resolved Hide resolved
hal/arm/scb.c Outdated Show resolved Hide resolved
@agkaminski agkaminski force-pushed the agkaminski/nvic_unite branch 4 times, most recently from b65a447 to 248b216 Compare August 9, 2024 15:00
hal/arm/scb.c Outdated Show resolved Hide resolved
@agkaminski agkaminski force-pushed the agkaminski/nvic_unite branch 5 times, most recently from 3ed3dc5 to 8e01895 Compare August 9, 2024 15:51
@agkaminski agkaminski marked this pull request as draft August 9, 2024 15:54
hal/arm/nvic.c Outdated Show resolved Hide resolved
@agkaminski agkaminski force-pushed the agkaminski/nvic_unite branch 3 times, most recently from 3748329 to e072985 Compare September 13, 2024 13:37
@agkaminski agkaminski marked this pull request as ready for review September 13, 2024 14:01
@agkaminski
Copy link
Member Author

@anglov just to verify if it does not break your stuff

@anglov
Copy link
Member

anglov commented Sep 19, 2024

I really like this change as it remove a lot of duplicated code. I check it on DEND (checked low power) and NIL projects and at the first glance it looks ok!

Some general remarks (or ideas for future):

  • I don't like using "SCB" and "System Control Block" name
    According to Armv7-M Architecture Reference Manual (DDI0403E.e) and Armv8-M Architecture Reference Manual (DDI0553B.y) SCB is small part of System Control Space which also contain NVIC, Systick, MPU and other control, debug and id registers.
    It's confusing for the first time.
    Maybe more appropriate name should be "SCS", as for "System Control Space"?
    Maybe NVIC registers should also be used from one big SCS structure?
  • I see that interrupts.c on armv7m architectures differs mainly with includes and priority of interrupts. It probably should be revised and also use common implementation in the future.
  • It's worth considering if _init.S couldn't be shared between cores somehow.
    armv8m implementations differs mainly with interrupt size, hal entry point and cosmetic things and approaches if I didn't miss anything.
    In armv7m implementation it differs mainly with interrupt size FPU hard/soft implementation and .cpu directive. In cortex-m4 was also errata requiring additional dsb at intertupt dispatch, which was propagated to cortex-m7 too anyways.

Current refactoring is great step in good direction anyways.

Copy link
Member

@Darchiv Darchiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge improvement, nice! Just two remarks (for the future, PR can be merged as-is):

  • Check cache availability in _hal_scbCacheIsSupported() via Cache Control Identification Registers instead of relying solely on cpuid->PARTNO, because cache is a silicon option.
  • A few functions are missing, e.g. _imxrt_nvicGetPendingIRQ(). They were not used, but maybe they should not be scrapped if code already exists.

@Darchiv Darchiv merged commit dadb7d5 into master Sep 25, 2024
30 checks passed
@Darchiv Darchiv deleted the agkaminski/nvic_unite branch September 25, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants